**REPLICATION FILE STATA V.18.5**

**Set working directory**
global data "C:\Users\...\data"
*Create a file called "Replication file" within the working directory*
* Please replace the path below with the folder where the dataset of Latinobarometer 2011 is stored:
use "$data/Latinobarometro_2011_esp.dta", clear

***DEPENDENT VARIABLE CLEANING***

**Legalization Variable Cleaning**
gen legalization = P83N_A
replace legalization = . if P83N_A == -1
lab var legalization "Support for legalization"
*Recode Legalization
recode legalization (1=4) (2=3) (3=2) (4=1), generate(legalization_invertida)
replace legalization = legalization_invertida
*Rescale Legalization 0-100
recode legalization (1=0) (2=33.3333) (3=66.6666) (4=100)

***INDEPENDENT VARIABLES CLEANING***	
	
**Knows Consumer Variable Cleaning**	
gen kn_consumer = P80ST_D 
replace kn_consumer = 0 if kn_consumer == 2
*Set missing for -1 and -2
replace kn_consumer = . if kn_consumer == -2
replace kn_consumer = . if kn_consumer == -1
*Create variable where missing is treated as 0 
gen kn_consumer_2 = kn_consumer
replace kn_consumer_2 = 0 if kn_consumer == .

**Missing Knows Consumer Variable Cleaning**
gen kn_consumer_missing = 0
replace kn_consumer_missing = 1 if kn_consumer == .
replace kn_consumer_missing = 1 if kn_consumer == .
tab kn_consumer_missing

**Knows Seller or Buyer Variable Cleaning**
gen kn_seller_buyer = P80ST_E 
replace kn_seller_buyer = 0 if kn_seller_buyer == 2
*Set missing for -1 and -2
replace kn_seller_buyer = . if kn_seller_buyer == -2
replace kn_seller_buyer = . if kn_seller_buyer == -1
*Create variable where missing is treated as 0
gen kn_seller_2 = kn_seller_buyer
replace kn_seller_2 = 0 if kn_seller_buyer == .
tab kn_seller_2


**Missing Seller or buyer Cleaning**
gen kn_seller_missing = 0
replace kn_seller_missing = 1 if kn_seller_buyer == .
replace kn_seller_missing = 1 if kn_seller_buyer == .
tab kn_seller_missing

***CONTROL VARIABLES CLEANING***

**Age**
gen age = s17
lab var age "Age"
tab age

**Socioeconomic Appraisal**
gen socioeconomic_appraisal = S34
*Recode values
recode socioeconomic_appraisal (1=5) (2=4) (3=3) (4=2) (5=1), generate(socioeconomic_appraisal_b)
replace socioeconomic_appraisal = socioeconomic_appraisal_b

**Years of Education**
gen education = S21
gen years_education = education -1
*Merge: 11 years with incomplete technique + 12 years with complete technique
replace years_education = 11 if years_education == 11 | years_education == 15 
replace years_education = 12 if years_education == 12 | years_education == 16 
** Recoding 14 years = Incomplete university, 16 years = Complete university
replace years_education = 16 if years_education == 14
replace years_education = 14 if years_education == 13 
tab years_education 
lab def estudios 0 "No studies" 1 "1 year" 2 "2 years" 3 "3 years" 4 "4 years" 5 "5 years" 6 "6 years" 7 "7 years" 8 "8 years" 9 "9 years" 10 "10 years" 11 "11 years/Institute/academy/technical training incomplete" 12 "12 years/Institute/academy/technical training complete" 14 "14 years/University incomplete" 16 "16 years/University complete" 
lab val years_education estudios

**Women**
gen women = S16
lab var women "Women"
*Generate binary variable 0 and 1
replace women = 0 if women == 1
replace women = 1 if women == 2

***Creation of race variables***
gen race = S27
tab race, gen(razas)
tab race

**Asians**
tab razas3
gen asians = razas3
replace asians = . if race == .

**Black**
*Combine Black and Mulatto racial categories
gen black = razas4 + razas7
replace black = . if race == .

**Indigenous**
gen indigenous = razas5
replace indigenous = . if race == .

**Mestizos**
gen mestizo = razas6
replace mestizo = . if race == .

**White**
gen white = razas8
replace white = . if race == .


**Other race**
gen other_race = razas9
replace other_race = . if race == .


**Unknown race**
*Creating variable combining 'Don't know' and 'No answer' responses
gen not_kn_race = razas1 + razas2
replace not_kn_race = . if race == .
	
	
***Creation od religion variables***
gen religion = S18
tab religion, gen(religions)

**Catholics**
gen catholic = religions3
replace catholic = . if religion == .

**Christians**
*Creating variable combining christian religions
gen christian = religions4 + religions5 + religions6 + religions7 + religions8 + religions9 + religions10 + religions12
replace christian = . if religion == .

**Other religions**
*Creating variable combining jewish, afro american religions and other 
gen other_religion = religions11 + religions13 + religions17
replace other_religion = . if religion == .

**No answer religion**
*Creating variable combining 'Don't know' and 'No answer' responses
gen no_answer_religion = religions1 + religions2
replace no_answer_religion = . if religion == .
	
	
**No religion**
*Creating variable combining no religious, agnostic, ateist and none
gen non_religious = religions14 + religions15 + religions16 + religions18
replace non_religious = . if religion == .


**Party ID**
gen party_id = P39ST_A
tab party_id, gen(parties)
gen yes_party_id = parties2 
tab yes_party_id

**No party ID**
gen no_party_id = parties1 + parties3


**Creating ideology variables**
gen ideology = P76ST 
tab ideology, gen(ideologies)
tab P76ST, nolabel

**No answer ideology**
*Creting variable combining 'Don't know' and 'No answer' responses
gen no_answer_ideology = ideologies2 + ideologies3
tab no_answer_ideology

**Ideology left**
*Creating variable combining values from 0 to 4
gen left_ideology = ideologies4 + ideologies5 + ideologies6 + ideologies7 + ideologies8
	
**Ideology center**
*Creating variable combining value 5 and no ideology 
gen cen_ideology = ideologies9 + ideologies1

**Ideology right**
*Creating variable combining values 6 to 10
gen right_ideology = ideologies10 + ideologies11 + ideologies12 + ideologies13 + ideologies14

**Year**
gen year = 2011

**Support for democracy**
gen ing4 = P16ST_A
recode ing4 (-1 = .) (1=4) (2=3) (3=2) (4=1)
	
**Income**
gen income = S10ICC12
recode income (-2 -1 = .) (1=4) (2=3) (3=2) (4=1)
lab var income "Income Sufficiency"


***Saving new database***

keep legalization kn_consumer_2 kn_seller_2 kn_consumer_missing kn_seller_missing women age socioeconomic_appraisal years_education not_kn_race asians black indigenous mestizo other_race white no_answer_religion catholic christian other_religion non_religious yes_party_id no_party_id no_answer_ideology left_ideology cen_ideology right_ideology idenpa comdist ciudad tamciud reg year wt income ing4

***Replace with local route***
save "$data/Replication file/L1_temporal.dta", replace

****Latinobarometer 2013 Variable Cleaning****
**Set working directory**
* Please replace the path below with the folder where the dataset of Latinobarometer 2011 is stored:
use "$data/Latinobarometro2013.dta", clear

*Dropped values obtained in Spain
drop if idenpa == 724

***DEPENDENT VARIABLE CLEANING***
**Legalization Variable Cleaning**
gen legalization = P71N
replace legalization = . if P71N == -1
replace legalization = . if P71N == -2
replace legalization = . if P71N == -4
*Recode Legalization 0-100
recode legalization (1=0) (2=50) (3=100)


***INDEPENDENT VARIABLES CLEANING***	

**Knows Consumer Variable Cleaning**	
gen kn_consumer = P68ST_C 
replace kn_consumer = 0 if kn_consumer == 2
*Set missing for -1 and -2
replace kn_consumer = . if kn_consumer == -2
replace kn_consumer = . if kn_consumer == -1
replace kn_consumer = . if kn_consumer == -4
*Create variable where missing is treated as 0 
gen kn_consumer_2 = kn_consumer
replace kn_consumer_2 = 0 if kn_consumer == .


**Missing Knows Consumer Variable Cleaning**
gen kn_consumer_missing = 0
replace kn_consumer_missing = 1 if kn_consumer == .
replace kn_consumer_missing = 1 if kn_consumer == .
tab kn_consumer_missing

**Knows Seller or Buyer Variable Cleaning**
gen kn_seller_buyer = P68ST_D 
replace kn_seller_buyer = 0 if kn_seller_buyer == 2
*Set missing for -1 and -2
replace kn_seller_buyer = . if kn_seller_buyer == -2
replace kn_seller_buyer = . if kn_seller_buyer == -1
*Create variable where missing is treated as 0
gen kn_seller_2 = kn_seller_buyer
replace kn_seller_2 = 0 if kn_seller_buyer == .
tab kn_seller_2

**Missing Seller or buyer Cleaning**
gen kn_seller_missing = 0
replace kn_seller_missing = 1 if kn_seller_buyer == .
replace kn_seller_missing = 1 if kn_seller_buyer == .
tab kn_seller_missing

***CONTROL VARIABLES CLEANING***

**Age**
gen age = S11
lab var age "Age"
tab age

**Socioeconomic Appraisal**
gen socioeconomic_appraisal = S27
*Recode values
recode socioeconomic_appraisal (1=5) (2=4) (3=3) (4=2) (5=1), generate(socioeconomic_appraisal_b)
replace socioeconomic_appraisal = socioeconomic_appraisal_b

**Years of Education**
gen education = S17
gen years_education = education -1
replace years_education = . if education == -5
replace years_education = . if education == -4
*Merge: 11 years with incomplete technique + 12 years with complete technique
replace years_education = 11 if years_education == 11 | years_education == 15 
replace years_education = 12 if years_education == 12 | years_education == 16 
* Recoding 14 years = Incomplete university, 16 years = Complete university
replace years_education = 16 if years_education == 14
replace years_education = 14 if years_education == 13 
tab years_education 
lab def estudios 0 "No studies" 1 "1 year" 2 "2 years" 3 "3 years" 4 "4 years" 5 "5 years" 6 "6 years" 7 "7 years" 8 "8 years" 9 "9 years" 10 "10 years" 11 "11 years/Institute/academy/technical training incomplete" 12 "12 years/Institute/academy/technical training complete" 14 "14 years/University incomplete" 16 "16 years/University complete" 
lab val years_education estudios
tab years_education

**Women**
gen women = S10
lab var women "Women"
*Generate binary variable 0 and 1
replace women = 0 if women == 1
replace women = 1 if women == 2

***Creation of race variables***
gen race = S21
tab race, gen(razas)
tab race

**Asians**
tab razas3
gen asians = razas3
replace asians = . if race == .

**Black**
*Combine Black and Mulatto racial categories
gen black = razas4 + razas7
replace black = . if race == .

**Indigenous**
gen indigenous = razas5
replace indigenous = . if race == .

**Mestizos**
gen mestizo = razas6
replace mestizo = . if race == .

**White**
gen white = razas8
replace white = . if race == .

**Other race**
gen other_race = razas9
replace other_race = . if race == .

**Unknown race**
*Creating variable combining 'Don't know' and 'No answer' responses
gen not_kn_race = razas1 + razas2
replace not_kn_race = . if race == .
	
***Creation of religion variables***
gen religion = S14
tab religion, gen(religions)

**Catholics**
gen catholic = religions3
replace catholic = . if religion == .

**Christians**
*Creating variable combining christian religions
gen christian = religions4 + religions5 + religions6 + religions7 + religions8 + religions9 + religions10 + religions12
replace christian = . if religion == .

**Other religions**
*Creating variable combining jewish, afro american religions and other 
gen other_religion = religions11 + religions13 + religions17
replace other_religion = . if religion == .

**No answer religion**
*Creating variable combining 'Don't know' and 'No answer' responses
gen no_answer_religion = religions1 + religions2
replace no_answer_religion = . if religion == .

**No religion**
*Creating variable combining no religious, agnostic, ateist and none
gen non_religious = religions14 + religions15 + religions16 + religions18
replace non_religious = . if religion == .

**Party ID**
gen party_id = P19STGBS
tab party_id, gen(parties)
gen yes_party_id = parties2 
tab yes_party_id
tab P19STGBS

**No party ID**
gen no_party_id = parties1 + parties3

**Creating ideology variables**
gen ideology = P41ST 
tab ideology, gen(ideologies)

**No answer ideology**
*Creting variable combining 'Don't know' and 'No answer' responses
gen no_answer_ideology = ideologies2 + ideologies3
tab no_answer_ideology

**Ideology left**
*Creating variable combining values from 0 to 4
gen left_ideology = ideologies4 + ideologies5 + ideologies6 + ideologies7 + ideologies8
	
**Ideology center**
*Creating variable combining value 5 and no ideology 
gen cen_ideology = ideologies9 + ideologies1

**Ideology right**
*Creating variable combining values 6 to 10
gen right_ideology = ideologies10 + ideologies11 + ideologies12 + ideologies13 + ideologies14

**Support for democracy**
gen ing4 = P43ST_A
recode ing4 (-2 -1 = .) (1=4) (2=3) (3=2) (4=1)	

	
**Income**
gen income = S6
recode income (-2 -1 = .) (1=4) (2=3) (3=2) (4=1)

**Year**
gen year = 2013

***Saving new database***
keep legalization kn_consumer_2 kn_seller_2 kn_consumer_missing kn_seller_missing women age socioeconomic_appraisal years_education not_kn_race asians black indigenous mestizo other_race white no_answer_religion catholic christian other_religion non_religious yes_party_id no_party_id no_answer_ideology left_ideology cen_ideology right_ideology idenpa comdist ciudad tamciud reg year wt income ing4

***Replace with local route***
save "$data/Replication file/L2_temporal.dta", replace



****Latinobarometer 2015 Variable Cleaning****

*Set working directory
* Please replace the path below with the folder where the dataset of Latinobarometer 2011 is stored:
use "$data/Latinobarometro_2015_Esp.dta", clear

***DEPENDENT VARIABLE CLEANING***

**Legalization Variable Cleaning**
gen legalization = P69ST_B
replace legalization = . if P69ST_B == -1
lab var legalization "Support for legalization"
*Recode Legalization
recode legalization (1=4) (2=3) (3=2) (4=1), generate(legalization_invertida)
replace legalization = legalization_invertida
*Rescale Legalization 0-100
recode legalization (1=0) (2=33.3333) (3=66.6666) (4=100)

***INDEPENDENT VARIABLES CLEANING***	
	
**Knows Consumer Variable Cleaning**	
gen kn_consumer = P61ST_A 
replace kn_consumer = 0 if kn_consumer == 2
*Set missing for -1 and -2
replace kn_consumer = . if kn_consumer == -2
replace kn_consumer = . if kn_consumer == -1
*Create variable where missing is treated as 0 
gen kn_consumer_2 = kn_consumer
replace kn_consumer_2 = 0 if kn_consumer == .

**Missing Knows Consumer Variable Cleaning**
gen kn_consumer_missing = 0
replace kn_consumer_missing = 1 if kn_consumer == .
replace kn_consumer_missing = 1 if kn_consumer == .
tab kn_consumer_missing

**Knows Seller or Buyer Variable Cleaning**
gen kn_seller_buyer = P61ST_B 
replace kn_seller_buyer = 0 if kn_seller_buyer == 2
*Set missing for -1 and -2
replace kn_seller_buyer = . if kn_seller_buyer == -2
replace kn_seller_buyer = . if kn_seller_buyer == -1
*Create variable where missing is treated as 0
gen kn_seller_2 = kn_seller_buyer
replace kn_seller_2 = 0 if kn_seller_buyer == .
tab kn_seller_2

**Missing Seller or buyer Cleaning**
gen kn_seller_missing = 0
replace kn_seller_missing = 1 if kn_seller_buyer == .
replace kn_seller_missing = 1 if kn_seller_buyer == .
tab kn_seller_missing

***CONTROL VARIABLES CLEANING***

**Age**
gen age = S13
lab var age "Age"
tab age

**Socioeconomic Appraisal**
gen socioeconomic_appraisal = S29
*Recode values
recode socioeconomic_appraisal (1=5) (2=4) (3=3) (4=2) (5=1), generate(socioeconomic_appraisal_b)
replace socioeconomic_appraisal = socioeconomic_appraisal_b

**Years of Education**
gen education = S19
gen years_education = education -1
*Merge: 11 years with incomplete technique + 12 years with complete technique
replace years_education = 11 if years_education == 11 | years_education == 15 
replace years_education = 12 if years_education == 12 | years_education == 16 
** Recoding 14 years = Incomplete university, 16 years = Complete university
replace years_education = 16 if years_education == 14
replace years_education = 14 if years_education == 13 
tab years_education 
lab def estudios 0 "No studies" 1 "1 year" 2 "2 years" 3 "3 years" 4 "4 years" 5 "5 years" 6 "6 years" 7 "7 years" 8 "8 years" 9 "9 years" 10 "10 years" 11 "11 years/Institute/academy/technical training incomplete" 12 "12 years/Institute/academy/technical training complete" 14 "14 years/University incomplete" 16 "16 years/University complete" 
lab val years_education estudios

**Women**
gen women = S12
lab var women "Women"
*Generate binary variable 0 and 1
replace women = 0 if women == 1
replace women = 1 if women == 2

***Creation of race variables***
gen race = S23
tab race, gen(razas)
tab race

**Asians**
tab razas3
gen asians = razas3
replace asians = . if race == .

**Black**
*Combine Black and Mulatto racial categories
gen black = razas4 + razas7
replace black = . if race == .



**Indigenous**
gen indigenous = razas5
replace indigenous = . if race == .

**Mestizos**
gen mestizo = razas6
replace mestizo = . if race == .

**White**
gen white = razas8
replace white = . if race == .


**Other race**
gen other_race = razas9
replace other_race = . if race == .


**Unknown race**
*Creating variable combining 'Don't know' and 'No answer' responses
gen not_kn_race = razas1 + razas2
replace not_kn_race = . if race == .

	
***Creation of religion variables***
gen religion = S16
tab religion, gen(religions)

**Catholics**
gen catholic = religions3
replace catholic = . if religion == .

**Christians**
*Creating variable combining christian religions
gen christian = religions4 + religions5 + religions6 + religions7 + religions8 + religions9 + religions10 + religions12
replace christian = . if religion == .

**Other religions**
*Creating variable combining jewish, afro american religions and other 
gen other_religion = religions11 + religions13 + religions17
replace other_religion = . if religion == .

**No answer religion**
*Creating variable combining 'Don't know' and 'No answer' responses
gen no_answer_religion = religions1 + religions2
replace no_answer_religion = . if religion == .	
	
**No religion**
*Creating variable combining no religious, agnostic, ateist and none
gen non_religious = religions14 + religions15 + religions16 + religions18
replace non_religious = . if religion == .	


**Party ID**
gen party_id = P30STGBS
tab party_id, gen(parties)
gen yes_party_id = parties2 
tab yes_party_id

**No party ID**
gen no_party_id = parties1 + parties3

**Creating ideology variables**
gen ideology = P27ST
tab ideology, gen(ideologies)

**No answer ideology**
*Creting variable combining 'Don't know' and 'No answer' responses
gen no_answer_ideology = ideologies2 + ideologies3
tab no_answer_ideology

**Ideology left**
*Creating variable combining values from 0 to 4
gen left_ideology = ideologies4 + ideologies5 + ideologies6 + ideologies7 + ideologies8
	
**Ideology center**
*Creating variable combining value 5 and no ideology 
gen cen_ideology = ideologies9 + ideologies1

**Ideology right**
*Creating variable combining values 6 to 10
gen right_ideology = ideologies10 + ideologies11 + ideologies12 + ideologies13 + ideologies14
	
**Year**
gen year = 2015

**Support for democracy**
gen ing4 = P13ST_A
recode ing4 (-2 -1 = .) (1=4) (2=3) (3=2) (4=1)	
	
**Income**
gen income = S4
recode income (-2 -1 = .) (1=4) (2=3) (3=2) (4=1)
	
***Saving new database***
keep legalization kn_consumer_2 kn_seller_2 kn_consumer_missing kn_seller_missing women age socioeconomic_appraisal years_education not_kn_race asians black indigenous mestizo other_race white no_answer_religion catholic christian other_religion non_religious yes_party_id no_party_id no_answer_ideology left_ideology cen_ideology right_ideology idenpa comdist ciudad tamciud reg year wt income ing4

***Replace with local route***
save "$data/Replication file/L3_temporal.dta", replace
****APPEND ALL DATASETS****

*Load the first dataset
use "$data/Replication file/L1_temporal.dta", clear
*Append the second dataset
append using "$data/Replication file/L2_temporal.dta"
*Append the third dataset
append using "$data/Replication file/L3_temporal.dta"
*Save the combined dataset
save "$data/Replication file/L2_COMPLETE.dta", replace

***VARIABLES***
*generate a variable for those who know either a user, buyer, or seller. 
egen kn_any_2 = rowtotal(kn_consumer_2 kn_seller_2)
recode kn_any_2 (2 =1)
*Generate an indicator for those who did not answer the question (2.32%)
gen kn_any_missing = 0
replace kn_any_missing = 1 if kn_consumer_missing == 1 & kn_seller_missing == 1
*Rescale age, years of education, socioeconomic appraisal and the size of the city to go from 0 to 1*
gen tamciud_2 = (tamciud - 1) / (8 - 1)
gen age_2 = (age - 16) / (99 - 16)
gen years_education_2 = (years_education - 0) / (16 - 0)
gen socioeconomic_appraisal_2 = (socioeconomic_appraisal - 1) / (5 - 1)
*Generate lagged country-year variables
*Create a countryyear categorical variable
egen countryyear = group(idenpa year)
*Proportion Knowing a User, Buyer or Seller
*Now get a country-year proportion
sort idenpa year 
egen KNOWS = mean(kn_any_2), by(countryyear)
*Now get the 2-year lag
forval j = 1/2 {
rangestat KNOWSlag`j' = KNOWS, interval(year -`j' -`j') by(idenpa)
}
gen KNOWSlag2r = KNOWSlag2*100
*Legalization
*First create an auxiliary 0 to 1 variable.
gen legalization_2 = (legalization - 0) / (100 - 0)
*Now get a country-year proportion
egen LEGALIZATION = mean(legalization_2), by(countryyear)
*Now get the 2 year lag
forval j = 1/2 {
rangestat LEGALIZATIONlag`j' = LEGALIZATION, interval(year -`j' -`j') by(idenpa)
}
gen LEGALIZATIONlag2r = LEGALIZATIONlag2*100

***ANALYSES***
*generate PSUs*
egen psu = group(comdist ciudad reg idenpa year)
*set up complex sampling design*
svyset psu [pweight=wt]
*global macros*
global demographic "women age_2 socioeconomic_appraisal_2 years_education_2 not_kn_race asians black indigenous mestizo other_race no_answer_religion catholic christian other_religion tamciud_2"
global political "yes_party_id no_answer_ideology left_ideology right_ideology"
*FIGURE 1 – GET THE ESTIMATES AND PREDICTED VALUES
svy: reg legalization kn_any_2 kn_any_missing  $demographic $political i.countryyear
estimates store INDIVIDUAL

*FIGURE 1 – DRAW THE FIGURE

coefplot INDIVIDUAL, ///
coeflabels( ///
kn_any_2 = "{bf:Contact}" ///
women = "Women" ///
age_2= "Age" ///
socioeconomic_appraisal_2= "Socioeconomic Appraisal" ///
years_education_2= "Education (Years)" ///
asians= "Asian vs. White" ///
black= "Black vs. White" ///
indigenous= "Indigenous vs. White" ///
mestizo= "Mestizo vs. White" ///
catholic= "Catholic vs. Atheist-None" ///
christian= "Christian vs. Atheist-None" ///
yes_party_id= "Identifies with Party" ///
left_ideology= "Left vs. Center Ideology" ///
right_ideology= "Right vs. Center Ideology") ///
drop(_cons *.countryyear kn_any_missing not_kn_race other_race no_answer_religion other_religion no_answer_ideology) ///
msize(small) ///
grid(none) ///
levels(99 95 90) ciopts(lc(%25 %50 %100) recast(. rcap rcap)) ///
scale (1) ///
xsize(12) ysize(8) ///
mlabposition(1.3) ///
xlab(-15(5)10) ///
mlabel("{it:p} = " + string(@pval,"%9.3f"))  mlabcolor(none) ///
addplot(scatter @at @ul if @plot==1, ms(i) mlabel(@mlbl) mlabsize(vsmall) pstyle(p2)) ///
mlabp(2) ///
scheme(s2color) ///
xline(0, lp(dash))	///
graphregion(color(white)) ///
caption("{it:N=57,900}", ring(0) pos(5)) ///
xtitle(Marginal Treatment Effects) 

*FIGURE 2 – GET THE ESTIMATES AND PREDICTED VALUES

svy: reg legalization kn_any_2 kn_any_missing  $demographic $political i.countryyear
margins, at(kn_any_2 = (0 1))

* FIGURE 2 – DRAW THE FIGURE

marginsplot,  recast(bar) plotopts(barw(.2)) ///
ylab(20(2.5)30) ///
xlab(0 "No" 1 "Yes") ///
ytitle("Predicted Support for Legalization") ///
xtitle("Contact with a Consumer, Seller, or Buyer") ///
plotregion(margin(30 30 0 0)) ///
xsize(9) ysize(5) ///
scheme(s2color) ///
plot1opts(color(navy%40)) ///
scale (1.2) ///
graphregion(color(white)) ///
text(25 0.5 "{&Delta}= 3.57", placement(n)) ///
title("")

*FIGURE 3 - GET THE ESTIMATES AND PREDICTED VALUES

*Individual Model ANY
qui svy: reg legalization kn_any_2 kn_any_missing  $demographic $political ib484.idenpa if year == 2011
margins, dydx(kn_any_2)
qui svy: reg legalization kn_any_2 kn_any_missing $demographic $political ib484.idenpa if year == 2013
margins, dydx(kn_any_2)
qui svy: reg legalization kn_any_2 kn_any_missing $demographic $political ib484.idenpa if year == 2015
margins, dydx(kn_any_2)
qui svy: reg legalization kn_any_2 kn_any_missing $demographic $political ib2011.year#ib484.idenpa
margins, dydx(kn_any_2)

*Individual Model DISAGREGATED
qui svy: reg legalization kn_consumer_2 kn_seller_2 kn_consumer_missing kn_seller_missing  $demographic $political  ib484.idenpa if year == 2011
margins, dydx(kn_consumer_2 kn_seller_2)
qui svy: reg legalization kn_consumer_2 kn_seller_2 kn_consumer_missing kn_seller_missing  $demographic $political  ib484.idenpa if year == 2013
margins, dydx(kn_consumer_2 kn_seller_2)
qui svy: reg legalization kn_consumer_2 kn_seller_2 kn_consumer_missing kn_seller_missing  $demographic $political  ib484.idenpa if year == 2015
margins, dydx(kn_consumer_2 kn_seller_2)
qui svy: reg legalization kn_consumer_2 kn_seller_2 kn_consumer_missing kn_seller_missing  $demographic $political ib2011.year#ib484.idenpa 
margins, dydx(kn_consumer_2 kn_seller_2)

*FIGURE 3 – SET THE MATRIX

*(PANEL 1) create a matrix of coefficients
matrix Any_coefficient = ( 3.051451, 4.282628, 3.194162, 3.567761)
*Create a matrix of standard errors
matrix Any_se = ( .8700111,  .608529, .5381973, .3883719)
*Give the same titles to the columns
matrix colnames Any_coefficient =  2011 2013 2015 Pooled
matrix colnames Any_se =  2011 2013 2015 Pooled			
*verify the matrix
matrix list Any_coefficient
matrix list Any_se		
*(PANEL 2) create a matrix of coefficients
matrix Consumer_coefficient = (2.261905,  4.436606 ,  3.079985,  3.28643)
*Create a matrix of standard errors
matrix Consumer_se = ( .8992995 ,  .7402569 ,  .6055105,  .430599)
*Give the same titles to the columns
matrix colnames Consumer_coefficient =  2011 2013 2015 Pooled
matrix colnames Consumer_se =  2011 2013 2015 Pooled 			
*verify the matrix
matrix list Consumer_coefficient
matrix list Consumer_se		
*( PANEL 3) create a matrix of coefficients
matrix Market_coefficient = ( 1.463153, .3022913 , .9901326 , .9805837)
*Create a matrix of standard errors
matrix Market_se = ( .975457  , .9846187 ,  .6863256, .506968)
*Give the same titles to the columns
matrix colnames Market_coefficient =  2011 2013 2015 Pooled
matrix colnames Market_se =  2011 2013 2015 Pooled
			
*FIGURE 3 – DRAW THE FIGURE 

coefplot matrix(Any_coefficient), se(Any_se) bylabel(Contact) || ///
matrix(Consumer_coefficient), se(Consumer_se) bylabel(Relational Contact{sup:a}) || ///
matrix(Market_coefficient), se(Market_se) bylabel(Distant/Anonymous Contact{sup:b}) ||, ///
coeflabels( ///
Pooled = "{bf:Pooled Model}" ///
2011 = "2011" ///
2013 = "2013" ///
2015 = "2015" ///
, labsize(medium)) ///
xlabel(-8(2)8) ///
xtitle("Average Marginal Effet on Support for Legalization") ///
levels(99 95 90) ciopts(lc(%25 %50 %100) recast(. rcap rcap)) ///
graphregion(fcolor(white)) /// 
xsize(8) ysize(5) ///
grid(none) ///
mlabel("{it:p} = " + string(@pval,"%9.3f")) mlabsize(small) ///
mlabp(1) ///
scale(1.3) ///
byopts(row(1)) /// ALL GRAPHS IN A SINGLE ROW///
graphregion(color(white)) ///
scheme(s2color) ///
xline(0, lp(dash))	

*FIGURE 4

xtmixed legalization LEGALIZATIONlag2 KNOWSlag2 kn_any_2 kn_any_missing $demographic $political [pweight=wt] || countryyear:, var	
estimates store HLM
*Draw the figure using coefplot
coefplot HLM, ///
coeflabels( ///
KNOWSlag2 = "{bf:AVG. CONTACT{sub:t-1,j}}" ///
LEGALIZATIONlag2 = "AVG. LEGALIZATION{sub:t-1,j}" ///
kn_any_2 = "{bf:Contact{sub:ij}}" ///
women = "Women" ///
age_2= "Age" ///
tamciud_2 = "Size of the City" ///
socioeconomic_appraisal_2= "Socioeconomic Appraisal" ///
years_education_2= "Education (Years)" ///
asians= "Asian vs. White" ///
black= "Black vs. White" ///
indigenous= "Indigenous vs. White" ///
mestizo= "Mestizo vs. White" ///
catholic= "Catholic vs. Atheist-None" ///
christian= "Christian vs. Atheist-None" ///
yes_party_id= "Identifies with Party" ///
left_ideology= "Left vs. Center Ideology" ///
right_ideology= "Right vs. Center Ideology") ///
drop(_cons *.year *.idenpa kn_any_missing not_kn_race other_race no_answer_religion other_religion no_answer_ideology LEGALIZATIONlag2r) ///
msize(small) ///
grid(none) ///
levels(99 95 90) ciopts(lc(%25 %50 %100) recast(. rcap rcap)) ///
order(KNOWSlag2 kn_any_2 $demographic $political) ///
scale (1.2) ///
xsize(8) ysize(4.5) ///
mlabel("{it:p} = " + string(@pval,"%9.3f"))  mlabcolor(none) ///
addplot(scatter @at @ul if @plot==1, ms(i) mlabel(@mlbl) mlabsize(vsmall) pstyle(p2)) ///
mlabp(2) ///
scheme(s2color) ///
xline(0, lp(dash))	///
graphregion(color(white)) ///
caption("{it:N=39,070}", ring(0) pos(5)) ///
xtitle(Marginal Treatment Effects) 
	
*FIGURE 5

xtmixed legalization LEGALIZATIONlag2 KNOWSlag2 kn_any_2 kn_any_missing $demographic $political [pweight=wt] || countryyear:, var
margins, at(KNOWSlag2=(0(.05).55))
*Draw the figure using marginsplot
marginsplot, ///
recast(line) ///
plot1opts(lcolor(dknavy%50)) ///
ciopt(color(dknavy%20) lwidth(none)) ///
recastci(rarea) ///
xsize(10) ysize(5) ///
scale(1.1) ///
scheme(s2color) ///
ytitle("Support for Legalization", size(medium)) ///
title("") ///
graphregion(color(white)) ///
xtitle("Proportion of Citizens Who Had Contact with a Drug User, Buyer or Seller in the Previous Wave", size(medium)) 

